﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Toybox.NicoSharp.Controls.Url
{
	/// <summary>
	/// UrlControl
	/// </summary>
	[TemplatePart(Name = "UrlTextBox", Type = typeof(TextBox))]
	[TemplatePart(Name = "ConnectButton", Type = typeof(Button))]
	public partial class UrlControl : Control
	{

		#region [Static]

		static UrlControl()
		{
			DefaultStyleKeyProperty.OverrideMetadata(
				typeof(UrlControl), new FrameworkPropertyMetadata(typeof(UrlControl)));
		}

		#endregion [Static]


		#region [DependencyProperty]

		public static readonly DependencyProperty PropertyUrl =
			DependencyProperty.Register("Url", typeof(Uri), typeof(UrlControl),
				new FrameworkPropertyMetadata(null, new PropertyChangedCallback(PropertyUrlChangedCallback)));

		private static void PropertyUrlChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			Uri value = e.NewValue as Uri;
			if (value == null) return;




		}

		#endregion  [DependencyProperty]


		#region Constructor

		//public UrlControl()
		//	: base()
		//{
		//	this.TextBox = this.
		//}

		#endregion Constructor


		#region Public Member

		public Uri Url
		{
			get { return this.GetValue(PropertyUrl) as Uri; }
			set { this.SetValue(PropertyUrl, value); }
		}

		#endregion Public Member

		#region Protected Member

		protected TextBox UrlTextBox
		{
			get { return this._urlTextBox; }
			set
			{
				if (this._urlTextBox != null)
				{
					this._urlTextBox.TextChanged -= _urlTextBox_TextChanged; 
				}

				this._urlTextBox = null;

				if (this._urlTextBox != null)
				{
					this._urlTextBox.TextChanged += _urlTextBox_TextChanged;
				}
			}
		}
		private TextBox _urlTextBox;


		#endregion Protected Member

		#region Protected Methods

		protected virtual void _urlTextBox_TextChanged(object sender, TextChangedEventArgs e)
		{
		}

		#endregion Protected Methods

	}
}